package com.yuan.leet_note.tree;

import com.yuan.leet_note.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ListTree
 * @Description: TODO
 * @Author MrYuan
 * @Date: 2021/6/28 17:56
 * @Version 1.0
 */
public class ListTree {
    static int i1 = 0;
    static int i2 = 0;
    static int i3 = 0;

    //二叉树的遍历,分别按照二叉树先序，中序和后序打印所有的节点。
    public static int[][] listTree(TreeNode head) {
        if (head == null) return null;
        int[][] trees = new int[3][getSize(head)];
        getOreder(head, trees);
        return trees;
    }

    private static void getOreder(TreeNode head, int[][] trees) {
        if (head == null) return;
        trees[0][i1++] = head.val;
        getOreder(head.left, trees);
        trees[1][i2++] = head.val;
        getOreder(head.right, trees);
        trees[2][i3++] = head.val;
    }

    private static void preOrder(TreeNode treeNode, List<Integer> list) {
        if (treeNode == null) return;
        list.add(treeNode.val);
        preOrder(treeNode.left, list);
        preOrder(treeNode.right, list);
    }

    private static void midOrder(TreeNode treeNode, List<Integer> list) {
        if (treeNode == null) return;
        preOrder(treeNode.left, list);
        list.add(treeNode.val);
        preOrder(treeNode.right, list);
    }

    private static int getSize(TreeNode head) {
        if (head == null) {
            return 0;
        }
        return 1 + getSize(head.left) + getSize(head.right);
    }

    static int ii = 0;

    public static void main(String[] args) {
        TreeNode hea = new TreeNode(1);
        TreeNode left = new TreeNode(2);
        TreeNode right = new TreeNode(3);
        hea.left = left;
        hea.right = right;
        int size = getSize(hea);
        int[][] ints = listTree(hea);
        for (int[] anInt : ints) {
            for (int i : anInt) {
                System.out.println(i);
            }
            System.out.println("--");
        }
//        List<Integer> arrayList = new ArrayList<>();
//
//        midOrder(hea, arrayList);
//        for (Integer integer : arrayList) {
//            System.out.println(integer);
//        }
    }
}